package com.martin.lib_base.base

import android.app.Activity
import android.app.Application
import android.os.Bundle
import com.martin.lib_base.LibBase
import com.martin.lib_base.helper.AppLifecycleHelper
import com.martin.lib_base.impl.ActivityLifecycleCallBackImpl
import com.martin.lib_base.interfaces.IRelease
import com.martin.lib_base.ktx.loge
import com.martin.lib_base.utils.ReleaseUtil
import com.tencent.mmkv.MMKV
import dev.DevUtils
import timber.log.Timber

open class BaseApplication : Application(), IRelease {

    override fun onCreate() {
        super.onCreate()
        AppLifecycleHelper.onAppCreate()

        // 注册Activity生命周期监听
        registerActivityLifecycleCallbacks(ActivityLifecycleCallBackImpl())

        //工具包-初始化
        DevUtils.init(this)

        //KeyValue工具-初始化
        MMKV.initialize(this)

        //debug模式下初始化内容
        if (LibBase.debug) {
            Timber.plant(Timber.DebugTree())
        }
    }

    override fun onTerminate() {
        super.onTerminate()
        AppLifecycleHelper.onAppTerminate()
        release()
    }

    override fun release() {
        ReleaseUtil.releaseAll()
    }
}